<!DOCTYPE html>
<html>

<% include ./user_component/head.ejs%>

<body class="layui-anim layui-anim-up">
  <div class="x-nav">
    <span class="layui-breadcrumb">
      <a href="/">首页</a>
      <a>
        <cite>题目列表</cite></a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
      href="javascript:location.replace(location.href);" title="刷新">
      <i class="layui-icon" style="line-height:30px">ဂ</i></a>
  </div>
  <div class="x-body">
    <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加题目','/question/questionAdd',1000,600)"><i
          class="layui-icon"></i>添加题目</button>
      <span class="x-right" style="line-height:40px">共有数据：<%-number%>条</span>
    </xblock>
    <table class="layui-table">
      <thead>
        <tr>
          <th>
            <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i>
            </div>
          </th>
          <th>ID</th>
          <th>题目</th>
          <th>题目类型</th>
          <th>出题时间</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <% for (let i=0; i<data_h.length; i++){%>
        <tr>
          <td>
            <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i
                class="layui-icon">&#xe605;</i></div>
          </td>
          <td><%=data_h[i]._id%></td>
          <td><%=data_h[i].title%></td>
          <td><%=data_h[i].type%></td>
          <td><%=data_h[i].time%></td>

          <td class="td-status">
            <span class="layui-btn layui-btn-normal layui-btn-mini updata" name="<%=data_h[i]._id%>">编辑</span>
            <span class="layui-btn layui-btn-danger layui-btn-mini drop" name="<%=data_h[i]._id%>">删除</span></td></td>
        </tr>
        <%}%>
        </tbody>
      </table>
      <div class="page">
        <div id="test1"></div>
      </div>

    </div>
    <script>
      $('.updata').click(function () {
        var _id = $(this).attr('name');
        x_admin_show('人员信息', '/question/questionEditor?id=' + _id, 1000, 700);
      })
      layui.use('laypage', function () {
        var laypage = layui.laypage;
        //执行一个laypage实例
        laypage.render({
          elem: 'test1' //注意，这里的 test1 是 ID，不用加 # 号
          , count: <%=number%> //数据总数，从服务端得到,
        , curr: <%= page %> //获取起始页
        , jump: function (obj, first) {
          if (!first) { //一定要加此判断，否则初始时会无限刷新
            location.href = '?page=' + obj.curr;
          }
        }
        });
        });


      /*删除*/
      $('.drop').click(function () {
        console.log($(this).attr('name'));
        var _id = $(this).attr('name');
        layer.confirm('确认要删除吗？', function (index) {
          //发异步删除数据
          $.ajax({
            url: '/api/deleteQuestion',
            method: 'POST',
            header: {
              'content-type': 'application/json' // 默认值
            },
            data: {
              _id: _id
            },
            success: function (e) {
              $(this).parent("tr").remove();
              layer.msg(e, { icon: 1, time: 1000 });
              location.reload();
            },
            fail: function (err) {
              console.log(err);
            },
            complete: function (e) {
            }
          }
          )
        });
      })
      function delAll(argument) {
        var data = tableCheck.getData();
        layer.confirm('确认要删除吗？' + data, function (index) {
          //捉到所有被选中的，发异步进行删除
          layer.msg('删除成功', { icon: 1 });
          $(".layui-form-checked").not('.header').parents('tr').remove();
        });
      }
    </script>

</body>

</html>
